package com.example.test_demo.test;

import java.io.File;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import static java.util.Calendar.DAY_OF_MONTH;
import static java.util.Calendar.MONTH;

/**
 * @program: test
 * @description: 工具类
 * @author: yanghua
 * @create: 2020-08-19 11:57
 **/
public class utils {
    private static String path = "C:\\Users\\Hasee\\Desktop\\1111111.txt";
    private static String path2 = "C:\\Users\\Hasee\\Desktop\\222222.txt";
    public static void main(String[] args) throws ParseException {
        //将properties文件改成yml文件
        //proToyml(path);
        //toExcel(path);//转化成excel
        //readFile(path);//不带""
        //readFile1(path);//带""
        //readFile2(path);//sql注解转化
        //toMysql( path,path2);//创表语句转化

        //readFile3(path);//生成实体类
        readFile7(path);//生成实体类,用的少

        //readFile9(path);
        //readFile99(path);
        //hengGang(path);//生成实体类,用的少
        //readFile4(path);//将实体类的成员属性放入到map中
        //readFile5(path);//下划线转化成驼峰
        //readFile6(path);  //空格分隔



        //readFile8(path);
        //getTableName("TH5CLNT800.ZMMTUS00481");//TH5CLNT800.ZCATUS00010  转化成  ${@middleware.helper.TableName@USER_SAP_TABLE_NAME}
        //System.out.println("111@sss".contains("@"));
        //System.out.println("111@sss".split("@")[1]);
//        Calendar date = Calendar.getInstance();
//        String year = String.valueOf(date.get(Calendar.YEAR));
//        System.out.println(year);
//        System.out.println("20201483".substring(0,4));
//        SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//
//                    //要格式化的Date对象
//                   Date date=new Date();
//                   //使用format()方法格式化Date对象为字符串，返回字符串
//        System.out.println("格式化之前："+date);
//        String format = sdf1.format(date);//
//        System.out.println("格式化之hou："+format);
//        BigDecimal b1 = new BigDecimal("1.345050000");
//        BigDecimal b2 = new BigDecimal("");
//        System.out.println(b1);
//        System.out.println(b2);
//        System.out.println(rvZeroAndDot(b1.toString()));
//        System.out.println(rvZeroAndDot(b2.toString()));

//        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//        System.out.println(sdf.format(new Date()));
//        String OP_MULTIPLE_INVOICE_NUMBER= "UUS-Z202009200001";
//        String[] split = OP_MULTIPLE_INVOICE_NUMBER.split("-");
//            // 自增1，形成新的发票号
//        if(OP_MULTIPLE_INVOICE_NUMBER.contains(sdf.format(new Date()))){
//
//            OP_MULTIPLE_INVOICE_NUMBER = "UUS-Z"+new BigDecimal(split[1].substring(1)).add(new BigDecimal(1));
//            System.out.println(OP_MULTIPLE_INVOICE_NUMBER);
//        }else{
//            OP_MULTIPLE_INVOICE_NUMBER = "UUS-Z"+sdf.format(new Date())+ "0001";
//            System.out.println(OP_MULTIPLE_INVOICE_NUMBER);
//        }



    }
    public static void proToyml(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine().trim();
                if (str.contains("#")){
                    System.out.println(str);
                }else {
                    String[] split = str.split("=");

                    if (split.length>=2){

                        String[] split1 = split[0].split("\\.");

                        String space="";
                        for (int i = 0; i <split1.length ; i++) {

                            if (i==(split1.length-1)){
                                System.out.println(space+split1[i]+": "+split[1]);
                            }else {
                                System.out.println(space+split1[i]+": ");
                            }
                            space+="    ";
                        }
                    }
                }





            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    //转化成excel
    public static void toExcel(String path){
        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine();
                String s="";
                String[] split = str.split(";");
                for (int i = 0; i < split.length; i++) {
                    System.out.print(split[i].replace("\\s+","")+"  ");
                }


            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }



    public static String rvZeroAndDot(String s){
        if (s.isEmpty()) {
            return null;
        }
        if(s.indexOf(".") > 0){
            s = s.replaceAll("0+?$", "");//去掉多余的0
            s = s.replaceAll("[.]$", "");//如最后一位是.则去掉
        }
        return s;
    }
    //读取文件，切分处理
    public static void readFile(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine();
                //System.out.println(str);
                String[] split = str.split("--");
                System.out.println("        //"+split[1].trim());
                System.out.println("result.put(\""+split[0].split("\\.")[1].replace(",","").trim()+""+"\",  BaseHelper.to_s(lease.get(\""+split[0].split("\\.")[1].replace(",","").trim()+"\")));");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    public static void readFile99(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine().trim();

                if (str.contains("private")){
                    System.out.println(str.split("\\s+")[2].replace(";",","));
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    public static void readFile9(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine();
                //System.out.println(str);
                String[] split = str.replace("\'","").replace("`","").split("COMMENT");
                System.out.println("        //"+split[1].trim());

                if (split[0].contains("varchar")){
                    System.out.println("private String "+split[0].trim().split("\\s+")[0]+";");
                }else if(split[0].contains("smallint")){

                    System.out.println("private int "+split[0].trim().split("\\s+")[0]+";");
                }else if(split[0].contains("decimal")){

                    System.out.println("private BigDecimal "+split[0].trim().split("\\s+")[0]+";");
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    public static void readFile4(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine();
                //System.out.println(str);
                String[] split = str.split("--");
                System.out.println("        //"+split[1].trim());
                //System.out.println("result.put(\""+split[0].split("\\.")[1].replace(",","").trim()+""+"\",  BaseHelper.to_s(vo.get"+toTuoFeng(split[0].split("\\.")[1].replace(",","").trim())+"()));");
                System.out.println("result.put(\""+split[0].split("\\.")[1].replace(",","").trim()+""+"\",  vo.get"+toTuoFeng(split[0].split("\\.")[1].replace(",","").trim())+"());");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    //创表语句转化
    public static void toMysql(String path,String path2){
        Map<String, String> map = addCOMMENT(path2);
        try {
            Scanner in = new Scanner(new File(path));

            while (in.hasNextLine()){
                String str = in.nextLine();
                if (!(str==null||"".equals(str))){
                    //System.out.println(str);
                    String key =str.trim().split("\\s+")[0].replace("\"","").trim();
                            str =str
                                    .substring(0,str.length()-1)
                                    .replace("\"","`")
                                    .replace("BIGINT CS_FIXED GENERATED ALWAYS AS IDENTITY (START WITH 10000000000 INCREMENT BY 1)","bigint(20)")
                                    .replace("INTEGER CS_INT GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1)","bigint(20)")
                                    .replace("INTEGER CS_INT","bigint(20)")
                                    .replace("CS_INT","").replace("NVARCHAR","varchar")
                                    .replace("LONGDATE CS_LONGDATE","datetime DEFAULT NULL")
                                    .replace("DATE CS_DAYDATE","datetime DEFAULT NULL")
                                    .replace("CS_FIXED","")
                                    .replace("TEXT","LONGTEXT DEFAULT NULL")
                                    //.replace(",","")
                                    +" COMMENT "+"\'"+map.get(key)+"\'"+" ,";
                            System.out.println(str);





                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    //创表语句转化
    public static Map<String, String> addCOMMENT(String path){
        Map<String, String> map = new HashMap<>();
        try {
            Scanner in = new Scanner(new File(path));

            while (in.hasNextLine()){
                String str = in.nextLine().trim();
                if (!(str==null||"".equals(str))){
                    //System.out.println(str);
                    String[] split = str.split("is");
                    map.put(split[0].trim(),split[1].trim());
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return map;


    }

    private static String toTuoFeng(String s){
        String name=null;
        if (s.contains("_")){
            String[] s1 = s.split("_");
            if (s1.length==2){
                name = s1[0].substring(0,1)+s1[0].substring(1).toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase();
            }
            if (s1.length==3){
                name = s1[0].substring(0,1)+s1[0].substring(1).toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase();
            }
            if (s1.length==4){
                name = s1[0].substring(0,1)+s1[0].substring(1).toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase()+s1[3].substring(0,1)+s1[3].substring(1).toLowerCase();
            }
            if (s1.length==5){
                name = s1[0].substring(0,1)+s1[0].substring(1).toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase()+s1[3].substring(0,1)+s1[3].substring(1).toLowerCase()+s1[4].substring(0,1)+s1[4].substring(1).toLowerCase();
            }
        }else {

            name = s.toLowerCase();
        }
        return name;
    }
    public static void readFile8(String path){
        int k=0;
        BigDecimal cc=BigDecimal.ZERO;
        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String[] str = in.nextLine().split("\\|");
                for (int i = 0; i <str.length ; i++) {
                    String price = str[i].split("\\&")[1];
                    cc=cc.add(new BigDecimal(price));
                    k++;
                }
            }
            System.out.println("k="+k+" cc ="+cc);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    public static void hengGang(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String next = in.nextLine();
                //判断字符串是否包含空格
                if (next.contains(" ")){//有
                    String[] split = next.split("\\s+");
                    //第二个是纯数字
                    if (split[1].matches("[0-9]+")){//纯数字

                        System.out.println(split[1]+"-"+split[0]);
                    }else {//
                        System.out.println(next);
                    }

                }else {//没有
                    System.out.println(next);
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void readFile7(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String[] str = in.nextLine().split(";");
                for (int i = 0; i <str.length ; i++) {
                    System.out.println("@Excel(name = \""+str[i]+"\")");
                    System.out.println("private String "+str[i]+";");
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }

    public static void readFile6(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine();
                //System.out.println(str);
                String[] split = str.split("--");

                System.out.println("result.put(\""+split[0].trim()+""+"\",  \""+split[1].trim()+"\");");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    public static void getTableName(String path){

        Map<String, String> result = new HashMap<>();
        result.put("LHSH.H4RTCONTRACT_MULTIPLE_PAYMENTS",  "${@middleware.helper.TableName@RTCONTRACT_MULTIPLE_PAYMENTS}");
        result.put("LHSH.H4LOGISTICS_DISPORT_PLAN",  "${@middleware.helper.TableName@PHYSICAL_DISPORT_PLAN_TABLE_NAME}");
        result.put("LHSH.H4LH_YSHT_XG",  "${@middleware.helper.TableName@TRANSTORT_OP_DISC_PORT}");
        result.put("LHSH.H4SHIP_BROKERAGING",  "${@middleware.helper.TableName@SHIP_BROKERAGING}");
        result.put("LHSH.H4SHIP_AGENT",  "${@middleware.helper.TableName@SHIP_AGENT}");
        result.put("LHSH.H4LH_YSHT_ZG",  "${@middleware.helper.TableName@TRANSTORT_OP_LOAD_PORT}");
        result.put("_SYS_BIC.SINOPEC.ZBYY.LHSHYY/H4US_ZCATUS00010",  "${@middleware.helper.TableName@USER_SAP}");
        result.put("LHSH.H4LEASE_COST_ALLOCATION",  "${@middleware.helper.TableName@LEASE_ALLOCATION_DETAILS}");
        result.put("TH5CLNT800.ZSDTUS00040",  "${@middleware.helper.TableName@TH5CLNT800_ZSDTUS00040}");
        result.put("TH5CLNT800.ZMMTUS00480",  "${@middleware.helper.TableName@PHYSICAL_RECAP_EXES_TABLE_NAME}");
        result.put("TH5CLNT800.ZMMTUS01220",  "${@middleware.helper.TableName@PHYSICAL_EXES_SETTLEMENTS}");
        result.put("TH5CLNT800.ZMMTUS01670",  "${@middleware.helper.TableName@BANK_ACCOUNT}");
        result.put("TH5CLNT800.ZMMTUS00481",  "${@middleware.helper.TableName@PHYSICAL_RECAP_EXES1_TABLE_NAME}");
        result.put("LHSH.H4TC_VOYAGE_DEMURRAGE",  "${@middleware.helper.TableName@TC_VOYAGE_DEMURRAGE}");
        result.put("TH5CLNT800.ZSDTUS00024",  "${@middleware.helper.TableName@ERP_PHYSICAL_RECAPS_LQ_TABLE}");
        result.put("LHSH.H4TC_TRANSPORT_FREIGHT",  "${@middleware.helper.TableName@TC_V_TRANSPORT_FREIGHT}");
        result.put("LHSH.H4TCV_MISC_COST",  "${@middleware.helper.TableName@TC_V_MISC_COST}");
        result.put("LHSH.H4SHIP_DEMURRAGE",  "${@middleware.helper.TableName@TRANSTORT_OP_DEMURRAGE}");
        result.put("TH5CLNT800.ZFITUS027",  "${@middleware.helper.TableName@REC_TOTAL_TABLE}");
        result.put("TH5CLNT800.ZSDTUS00020",  "${@middleware.helper.TableName@PHYSICAL_RECAP_TABLE_NAME}");
        result.put("_SYS_BIC.SINOPEC.ZBYY.LHSHYY/H4US_ZMMTUS00480",  "${@middleware.helper.TableName@PHYSICAL_RECAP_EXES_VIEW_NAME}");
        result.put("TH5CLNT800.ZMMTUS00010",  "${@middleware.helper.TableName@OIL_TYPE_TABLE}");
        result.put("TH5CLNT800.ZMMTUS01650",  "${@middleware.helper.TableName@CUSTOMER_SUPPLIER_RELATION}");
        result.put("LHSH.H4SHIP_PACKAGE_RELATIONS",  "${@middleware.helper.TableName@SHIPPING_LEASE_PACKAGE_RELATIONS}");
        result.put("LHSH.H4LEASE",  "${@middleware.helper.TableName@SHIPPING_LEASE}");
        result.put("LHSH.H4LOGISTICS_NUM",  "${@middleware.helper.TableName@PHYSICAL_PACKAGING_NUM_TABLE_NAME}");
        result.put("TH5CLNT800.ZMMTUS00970",  "${@middleware.helper.TableName@PHYSICAL_COSTS_TABLE_NAME}");
        result.put("LHSH.H4TC_CONTRACT_COST",  "${@middleware.helper.TableName@TC_COST_MANAGEMENT}");
        result.put("LHSH.H4TC_VESSELS",  "${@middleware.helper.TableName@TIME_CHARTER_CONTRACT}");
        result.put("TH5CLNT800.ZSDTUS00080",  "${@middleware.helper.TableName@COST_TYPES}");
        result.put("_SYS_BIC.SINOPEC.ZBYY.LHSHYY/H4US_ZMMTUS00970",  "${@middleware.helper.TableName@PHYSICAL_COSTS_VIEW_NAME}");
        result.put("LHSH.H4TC_VESSEL_COST_SPLIT_VC_INFO",  "${@middleware.helper.TableName@TIME_CHARTER_VOYAGE}");
        result.put("TH5CLNT800.ZFIUS080",  "${@middleware.helper.TableName@RBKP_080}");
        result.put("LHSH.H4OPERATION_INSPECTION_DETAILS",  "${@middleware.helper.TableName@OPERATION_INSPECTION_DETAILS}");
        result.put("TH5CLNT800.ZCATUS00010",  "${@middleware.helper.TableName@USER_SAP_TABLE_NAME}");
        result.put("_SYS_BIC.SINOPEC.EDW.01_DATAMART_LAYER.007_H.CG.DF/HDF_SR_UK_MTMPRICE_PH5CLNT800",  null);

        System.out.println(result.get(path));
    }
    public static String readFile5(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine();
                //System.out.println(str);
                String[] split = str.split("--");
                String s = split[0].split("\\.")[1].replace(",", "").trim();
                if (s.contains("_")){
                    String[] s1 = s.split("_");
                    if (s1.length==2){
                        return s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase();
                    }
                    if (s1.length==3){
                        return s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase();
                    }
                    if (s1.length==4){
                        return s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase()+s1[3].substring(0,1)+s1[3].substring(1).toLowerCase();
                    }
                }else {

                    return s.toLowerCase();
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;

    }
    //读取文件，切分处理
    public static void readFile1(String path){

        try {
            Scanner in = new Scanner(new File(path));
            while (in.hasNextLine()){
                String str = in.nextLine();
                //System.out.println(str);
                String[] split = str.split("--");
                System.out.println("        //"+split[1].trim());
                System.out.println("result.put(\""+split[0].split("\\.")[1].replace(",","").trim()+""+"\", \"\" );");
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    //sql注解转化
    public static void readFile2(String path){

        try {
            Scanner in = new Scanner(new File(path));

            while (in.hasNextLine()){
                String str = in.nextLine();
                if (!(str==null||"".equals(str))){
                    //System.out.println(str);
                    String[] split = str.split("--");

                    System.out.println(split[0]+"       "+"<!-- "+split[1]+" -->");
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }
    public static void readFile3(String path){

        try {
            Scanner in = new Scanner(new File(path));

            while (in.hasNextLine()){
                String str = in.nextLine();
                if (!(str==null||"".equals(str))){
                    //System.out.println(str);
                    String[] split = str.split("--");

                    String s = split[0].split("\\.")[1].replace(",", "").trim();
                    String name=null;
                    if (s.contains("_")){
                        String[] s1 = s.split("_");
                        if (s1.length==2){
                            name = s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase();
                        }
                        if (s1.length==3){
                            name = s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase();
                        }
                        if (s1.length==4){
                            name = s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase()+s1[3].substring(0,1)+s1[3].substring(1).toLowerCase();
                        }
                        if (s1.length==5){
                            name = s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase()+s1[3].substring(0,1)+s1[3].substring(1).toLowerCase()+s1[4].substring(0,1)+s1[4].substring(1).toLowerCase();
                        }
                        if (s1.length==6){
                            name = s1[0].toLowerCase()+s1[1].substring(0,1)+s1[1].substring(1).toLowerCase()+s1[2].substring(0,1)+s1[2].substring(1).toLowerCase()+s1[3].substring(0,1)+s1[3].substring(1).toLowerCase()+s1[4].substring(0,1)+s1[4].substring(1).toLowerCase()+s1[5].substring(0,1)+s1[5].substring(1).toLowerCase();
                        }
                    }else {

                        name = s.toLowerCase();
                    }

                    System.out.println("@ApiModelProperty(value = "+"\""+split[1]+"\")");
                    System.out.println("private String "+name+";");
                }

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


    }


}
